<?php
/**
 * 回收站表
 * Created on 2022/8/23 17:46
 * Created by 管昌虎
 * Email guanchanghu626@163.com
 * @author 管昌虎
 */

namespace GuanChanghu\Models;

use Exception;

/**
 * @author 管昌虎
 * Class Recycle
 * @tag encryption free
 * @package GuanChanghu\Models\Traits\Recycled
 * Created on 2022/8/23 17:46
 * Created by 管昌虎
 * Email guanchanghu626@163.com
 */
class Recycle extends Model
{
    /**
     * @var string
     */
    protected $table = 'recycle';

    /**
     * 数值精度处理
     *
     * @var string[]
     */
    protected $casts = [
        'table' => 'string',
        'table_id' => 'string',
        'data' => 'array',
    ];

    /**
     * @param \Illuminate\Database\Eloquent\Model $model
     * @return Recycle
     * @throws Exception
     */
    protected static function recycle(\Illuminate\Database\Eloquent\Model $model): Recycle
    {
        return Recycle::initialize([
            'table' => get_class($model),
            'tableId' => $model->getKey(),
            'data' => $model->toArray(),
        ])->changes();
    }
}
